home *** CD-ROM | disk | FTP | other *** search
- Path: news-m01.ny.us.ibm.net!usenet
- From: bbogard@ibm.net
- Newsgroups: comp.lang.c++
- Subject: Re: What does this "const" mean?
- Date: 28 Feb 1996 16:39:52 GMT
- Message-ID: <4h20go$154o@news-s01.ny.us.ibm.net>
- References: <4h0j7u$htp@crcnis3.unl.edu>
- Reply-To: bbogard@ibm.net
- NNTP-Posting-Host: slip37-223-98.ibm.net
- X-Newsreader: IBM NewsReader/2 v1.2.5
-
- > I have some problems regarding this program segment:
- >
- > class intset {
- > // ...
- > void start(int& i) const { i = 0; }
- > int ok(int& i) const { return i<cursize; }
- > int next(int& i) const { return x[i++]; }
- > };
- >
- > What does "const" mean in this program segment? What role does
- >it play? In what kind of situation will we use "const" like this?
-
- the const after these functions, forces the implementation of these functions to not modify
- the object that contains these functions. In other words, any function with a const after its
- declaration can only look at data members in the object and not modify them. This also means
- that it can only call const functions in the same object and other objects.
-